package com.matrix.java.chap_07;

import com.matrix.java.util.ArrayUtil;

import java.util.Scanner;

/*
    指定等级
 */
public class Ex7_01 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the number of students: ");
        int studentNum = input.nextInt();
        System.out.print("Enter " + studentNum + " scores: ");
        int[] scoreArray = new int[studentNum];
        for (int i = 0; i < scoreArray.length; i++) {
            scoreArray[i] = input.nextInt();
        }
        input.close();

        int best = ArrayUtil.findMaxInArray(scoreArray);
        for (int i = 0; i < scoreArray.length; i++) {
            System.out.println("Student " + i + " score is " + scoreArray[i]
                    + " and grade is " + checkGrade(scoreArray[i], best));
        }
    }

    private static String checkGrade(int score, int best) {
        String grade;
        if (score >= best - 10) {
            grade = "A";
        } else if (score >= best - 20) {
            grade = "B";
        } else if (score >= best - 30) {
            grade = "C";
        } else if (score >= best - 40) {
            grade = "D";
        } else {
            grade = "F";
        }
        return grade;
    }
}
